import inquirer from 'inquirer'

console.log('inquirer:', inquirer);


//region 基本用法 --- prompt几大属性 type(input、number、...) 、validate、transformer、filter
// inquirer
//   .prompt([{
//     type: 'input',
//     name: 'yourName',
//     message: 'your name:',
//     //什么都不使用就会采用↓这个
//     default: 'nobody',
//     validate: function (value) {
//       // 如果用户输入的不是foo就会一直卡在当前流程不会继续往下询问
//       // return value === 'foo'
//
//       //返回false是不通过，返回true是放行
//       return true
//     },
//     transformer: function (value) {
//       // 返回的值会被用作最终展示在控制台上的值
//       // 比如你输入 ahhh, 显示的会是 [ahhh]
//       return `[${value}]`
//     },
//
//     //filter和transformer类似，但是它会影响最终的结果
//     /*
// ? your name: [@ff@]
// answers: { yourName: '@ff@' }
//     */
//     filter: function (value) {
//       return `@${value}@`
//     }
//   },
//   {
//     type: 'number', //不是数字会尽量转换为数字，实在不行就会变成NaN
//     name: 'yourNumberKey',
//     message: 'your number:',
//   }
//   ])
//   .then(answers => {
//     // Use user feedback for... whatever!!
//     console.log('answers:',answers)
//   })
//   .catch(error => {
//     if(error.isTtyError) {
//       // Prompt couldn't be rendered in the current environment
//       console.log('error.isTtyError:',error.isTtyError)
//     } else {
//       // Something else went wrong
//       console.log('error:',error)
//     }
//   })

/*
inquirer: {
  prompt: [Function: promptModule] {
    prompts: {
      list: [class ListPrompt extends Prompt],
      input: [class InputPrompt extends Prompt],
      number: [class NumberPrompt extends InputPrompt],
      confirm: [class ConfirmPrompt extends Prompt],
      rawlist: [class RawListPrompt extends Prompt],
      expand: [class ExpandPrompt extends Prompt],
      checkbox: [class CheckboxPrompt extends Prompt],
      password: [class PasswordPrompt extends Prompt],
      editor: [class EditorPrompt extends Prompt]
    },
    registerPrompt: [Function (anonymous)],
    restoreDefaultPrompts: [Function (anonymous)]
  },
  ui: {
    BottomBar: [class BottomBar extends UI],
    Prompt: [class PromptUI extends UI]
  },
  createPromptModule: [Function: createPromptModule],
  registerPrompt: [Function: registerPrompt],
  restoreDefaultPrompts: [Function: restoreDefaultPrompts],
  Separator: [class Separator]
}
? your name: 123
answers: { yourName: '123' }
*/

//endregion


//region 更多type: confirm (布尔值)、list和rawlist、expand、checkbox、password

inquirer
  .prompt([
    {
      type: 'confirm',
      name: 'choice',
      message: 'your choice:',
      default: false
    }
    //? your choice: Yes
    // answers: { choice: true }

    /*, {
      type: 'list',
      name: 'listChoice',
      message: 'your list choice:',
      choices: [
        {name: 'a', value: 1},
        {name: 'b', value: 2},
        {name: 'c', value: 3}
      ],
      //index
      default: 0
    }*/
    //? your choice: No
    //? your choice2: b
    //answers: { choice: false, choice2: 2 }

    /*, {
      type: 'rawlist', //和list差不多，只是选择时的交互上稍微强点，不仅能通过箭头选择，还能自己输入
      name: 'rawlistChoice',
      message: 'your rawlist choice:',
      choices: [
        {name: 'a', value: 1},
        {name: 'b', value: 2},
        {name: 'c', value: 3}
      ],
      //index
      default: 0
    }*/
    //? your choice: Yes
    // ? your choice2: a
    // ? your choice3:
    //   1) a
    //   2) b
    //   3) c
    //   Answer:

    /*, {
      type: 'expand', //默认不会详细的展示所有选项， 只会输出 `? your expand choice: (Rgbh)`，括号里是你支持的所有选项的key，h是help（会撑开展示详细选项信息）
      name: 'expandChoice',
      message: 'your expand choice:',
      choices: [
        {key:'R',value:'red'},
        {key:'G',value:'green'},
        {key:'B',value:'blue'},
      ],
      //index
      default: 'red'
    }*/
    //? your expand choice: (Rgbh)
    //   r) red
    //   g) green
    //   b) blue
    //   h) Help, list all options
    //   Answer:


    , {
      type: 'checkbox',
      name: 'checkboxChoice',
      message: 'your checkbox choice:',
      choices: [
        {name: 'a', value: 1},
        {name: 'b', value: 2},
        {name: 'c', value: 3}
      ],
      //index
      default: 0
    }
    //通过空格选中一个，通过a全选，通过i反选，通过enter确认
    //
    //? your checkbox choice: (Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
    //  ( ) a
    //  (*) b
    // >(*) c

    /*, {
      type: 'password',
      name: 'password',
      message: 'your password',
      default: 'xxx'
    }*/
    //最初会展示
    //? your password [hidden] [input is hidden]
    //你开始输入后会展示
    //? your password [input is hidden]

    ,{
      type: 'editor',
      name: 'editor',
      message: 'your editor input',
      default: 'ffff'
    }
    //? your editor input Press <enter> to launch your preferred editor.
    //按回车后会打开一个临时文件进行编辑
    //windows就是一个txt文本编辑器、其它的linux系则是vim

  ])
  .then(answers => {
    // Use user feedback for... whatever!!
    console.log('answers:', answers)
  })
  .catch(error => {
    if (error.isTtyError) {
      // Prompt couldn't be rendered in the current environment
      console.log('error.isTtyError:', error.isTtyError)
    } else {
      // Something else went wrong
      console.log('error:', error)
    }
  })

//endregion
